<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    function upload_file($request,$arr){
        $allowed_extensions = ["png", "jpg", "gif", "jpeg"];
        $msg = null;
        if ($request->file($arr["name"])) {
            if ($request->file($arr["name"])->getClientOriginalExtension() && !in_array($request->file($arr["name"])->getClientOriginalExtension(), $allowed_extensions)) {
                $msg[]=$arr['warn1'];
            }else{
                if($arr['judgesize']){
                    $size = getimagesize($request->file($arr["name"]));
                    $width = $size[0];
                    $height = $size[1];
                    if($width!=$arr['width'] || $height!=$arr['height'] || $width/$height!=$arr['width']/$arr['height'] ){
                        $msg[]=$arr['warn2'];
                    }

                }

            }
        }
        return $msg;
    }
}
